//
//  MainMenu.m
//  blackjack
//
//  Created by Thi Nguyen Tran on 3/13/10.
//  Copyright 2010 Epsilon. All rights reserved.
//

#import "MainMenu.h"
@interface MainMenu(Private)
- (void)addQuitAndNext;
UIImageView *label_;
int selectedButton_;
@end


@implementation MainMenu
@synthesize delegate;


- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
		
		//backgroud
        UIImageView *bg = [[UIImageView alloc] initWithFrame:frame];
		[bg setImage:[UIImage imageNamed:@"menu_background.png"]];
		[self addSubview:bg];
		[bg release];
		
		//quit and next button
		[self addQuitAndNext];
		
		
		//init label
		label_ = [[UIImageView alloc] initWithFrame:CGRectMake(20, 70, 170, 50)];
		[self addSubview:label_];
		
		//init 4 buttons
		MainmenuButton *mainButton = [[MainmenuButton alloc] initWithType:BASIC_STRATEGY];	
		[mainButton setDelegate:self];
		[self addSubview:mainButton];
		[mainButton release];
		
		mainButton = [[MainmenuButton alloc] initWithType:CARD_COUNTING];	
		[mainButton setDelegate:self];
		[self addSubview:mainButton];
		[mainButton release];
		
		mainButton = [[MainmenuButton alloc] initWithType:TUTORIAL_AND_TIPS];	
		[mainButton setDelegate:self];
		[self addSubview:mainButton];
		[mainButton release];
		
		mainButton = [[MainmenuButton alloc] initWithType:INFORMATION];	
		[mainButton setDelegate:self];
		[self addSubview:mainButton];
		[mainButton release];
		
		[self basicButtonTouched];
    }
    return self;
}

- (void)addQuitAndNext
{
	//quit
	UIButton *quitBtn = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
	quitBtn.frame = CGRectMake(0, 420, 120, 60);
	[quitBtn setBackgroundImage:[UIImage imageNamed:@"menu_back_button_normal.png"] forState:UIControlStateNormal];
	[quitBtn setBackgroundImage:[UIImage imageNamed:@"menu_back_button_selected.png"] forState:UIControlStateSelected];
	[quitBtn addTarget:self	 action:@selector(quitButtonTouched) forControlEvents:UIControlEventTouchUpInside];
	[self addSubview:quitBtn];
	
	//next
	UIButton *nextBtn = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
	nextBtn.frame = CGRectMake(200, 420, 120, 60);
	[nextBtn setBackgroundImage:[UIImage imageNamed:@"menu_back_button_normal.png"] forState:UIControlStateNormal];
	[nextBtn setBackgroundImage:[UIImage imageNamed:@"menu_back_button_selected.png"] forState:UIControlStateSelected];
	[nextBtn addTarget:self	 action:@selector(nextButtonTouched) forControlEvents:UIControlEventTouchUpInside];
	[self addSubview:nextBtn];
	
}

- (void)tutorialButtonTouched
{
	UIImage *img = [UIImage imageNamed:@"menu_tutor_text.png"];
	[label_ setImage:img];
	selectedButton_ = TUTORIAL_AND_TIPS;
}
- (void)cardcountingButtonTouched
{
	UIImage *img = [UIImage imageNamed:@"menu_cardcounting_text.png"];
	[label_ setImage:img];
	selectedButton_ = CARD_COUNTING;
}
- (void)basicButtonTouched
{
	UIImage *img = [UIImage imageNamed:@"menu_basic_text.png"];
	[label_ setImage:img];
	selectedButton_ = BASIC_STRATEGY;
}
- (void)inforButtonTouched
{
	UIImage *img = [UIImage imageNamed:@"menu_infor_text.png"];
	[label_ setImage:img];
	selectedButton_ = INFORMATION;
}


- (void)nextButtonTouched
{
	[delegate chooseMode:selectedButton_];
}

- (void)quitButtonTouched
{
	[delegate exitApp];
}

- (void)dealloc {
	[label_ release];
    [super dealloc];
}


@end
